
export default {
    addCart(context, payload) {
        return new Promise((resolve, reject) => {
            //原来最开始不管三七二十一通通整个商品加入购物车 state.cartList.push(payload)
            //下为如果相同商品只是数量+1
            let oldProduct = context.state.cartList.find(item => item.iid === payload.iid)
            if (oldProduct) {
                context.commit("add_counter", oldProduct)
                resolve("当前商品数量+1")
            }
            else {
                payload.count = 1;
                //state.cartList.push(payload);
                context.commit("add_to_cart", payload)
                resolve("添加了新的商品")
            }
        })

    }
}